/****************************************
Figure B.18, Figure B.19
*****************************************/

/********************************
Figure B.18
********************************/

* Load marriage level data on FCM Types (Familinx)
use "$dir/Data/Original/FCM_Familinx.dta", clear
set scheme burd


keep if matching_first > 0 /* Keep only first cousin marriages */

/* Over Time */
egen year_bin = cut(year), at(1750(10)1950)
egen total_count = rowtotal(cm_fbd-cm_msd)
collapse (sum) cm_fbd cm_fsd cm_mbd cm_msd total_count, by(year_bin)


foreach var of varlist(cm_fbd-cm_msd){
gen `var'_share = `var'/total_count
}


tw ///
	(lpoly cm_fbd_share year_bin, lpattern("longdash")) ///
	(lpoly cm_fsd_share year_bin, lpattern("shortdash")) ///
	(lpoly cm_mbd_share year_bin) ///
	(lpoly cm_msd_share year_bin, lpattern("shortdash_dot")) ///
	, legend(cols(4) ///
	label (1 "FBD") label (2 "FSD") label (3 "MBD") label (4 "MSD") ///
	) ///
	note("") ///
	caption("Types of First Cousin Marriages over Time") yline(.25)
graph export "$dir/Output/TablesFigures/Graph_FCMType_Shares.png", replace

/********************************
Figure B.19
********************************/

* Load marriage level data on FCM Types (Familinx)
use "$dir/Data/Original/FCM_Familinx.dta", clear

collapse (mean) cm_fbd cm_fsd cm_mbd cm_msd match_any matching_first (firstnm) post_ban (rawsum) id_geni, by(state year)

keep if year <= 1940

label var cm_fbd "Type-1 first cousin marriages (marrying father's brother's daughter)"

lpoly cm_fbd year [aw = id_geni], noscatter bwidth(12) title("Type-1 first cousin marriages (geni)")
graph save "$dir/Output/TablesFigures/FBD_SY.gph", replace


* Load isonymy rates (state-year level)
use "$dir/Data/Final/Isonymy_sy.dta", clear
label var IsoObs_sy "Isonymous Marriages"

lpoly IsoObs_sy year [aw = N_sy], noscatter bwidth(4) title("Isonymous marriages (marriage records)") 
graph save "$dir/Output/TablesFigures/Isonymous_SY.gph", replace

gr combine "$dir/Output/TablesFigures/FBD_SY.gph" "$dir/Output/TablesFigures/Isonymous_SY.gph"
graph export "$dir/Output/TablesFigures/Graph_Iso_fcm2.png", replace

